//
//  HMMusicTool.m
//  04-黑马音乐
//
//  Created by apple on 15-3-29.
//  Copyright (c) 2015年 itcast. All rights reserved.
//

#import "HMMusicTool.h"
#import "HMMusic.h"
#import "MJExtension.h"

@implementation HMMusicTool

static NSArray *_musics;
static HMMusic *_playingMusic;
/**
 *  返回所以的歌曲
 *
 *  @return 所以的歌曲
 */
+ (NSArray *)musics
{
    if (_musics == nil) {
        _musics = [HMMusic objectArrayWithFilename:@"Musics.plist"];
    }
    return _musics;
}

+ (void)setPlayingMusic:(HMMusic *)playingMusic
{
    // if (_playingMusic == playingMusic) return;
    
    _playingMusic = playingMusic;
}

+ (HMMusic *)playingMusic
{
    return _playingMusic;
}

+ (HMMusic *)nextMusic
{
    NSInteger currentIndex = [_musics indexOfObject:_playingMusic];
    currentIndex++;
    
    if (currentIndex > _musics.count - 1) {
        currentIndex = 0;
    }
    
    HMMusic *nextMusic = _musics[currentIndex];
    
    _playingMusic = nextMusic;
    
    return nextMusic;
}

+ (HMMusic *)previousMusic
{
    NSInteger currentIndex = [_musics indexOfObject:_playingMusic];
    currentIndex--;
    
    if (currentIndex < 0) {
        currentIndex = _musics.count -1;
    }
    
    HMMusic *previousMusic = _musics[currentIndex];
    _playingMusic = previousMusic;
    
    return previousMusic;
}

@end
